home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / S / SurferPlus / Domouse.c next >
Encoding:
C/C++ Source or Header  |  1990-09-17  |  6.4 KB  |  281 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        domouse.c
  3.  
  4.     Contains:    mouse tracking routines
  5.     
  6.     Written by:    Mary Chan
  7.  
  8.     Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #pragma     load    <header.dump>
  13. #include    "TMIntf.h"
  14. #include    "globals.h"
  15.  
  16.  
  17. extern        Rect        visCacheRect;
  18. extern        Point        mycellSize;
  19. extern        Point        myslop;
  20.  
  21. /******************************************************************
  22. *    SwapPoint
  23. *        -    swap the two pass in starting and end point so that endptr > startptr.
  24. *
  25. *    inputs:
  26. *        startptr    -    starting point of the selection, top left, expect the 
  27. *                        address of the point.
  28. *        endptr        -    ending point of the selection, bottom right, expects address
  29. *
  30. ******************************************************************/
  31. SwapPoint( startptr, endptr )
  32. Point        *startptr ;
  33. Point        *endptr ;
  34. {
  35.     Point            tempptr ;
  36.     
  37.     if (  ( endptr->v < startptr->v) ||
  38.           ( endptr->v == startptr->v && endptr->h < startptr->h )
  39.        )
  40.     {
  41.         tempptr = *startptr ;
  42.         *startptr = *endptr ;
  43.         *endptr = tempptr ;
  44.     }
  45. }
  46.  
  47.  
  48.  
  49. /******************************************************************
  50. *    GetRegion
  51. *        -    return a region handle which encloses the region inside
  52. *            the two diagonal points.  Expects the points to be at the
  53. *            cell boundary.
  54. *
  55. *    inputs:
  56. *        regionhdl    -    region handle
  57. *        startptr    -    starting point of the selection, top left, expect the actual point
  58. *                        not the address of the point, less dereference.
  59. *        endptr        -    ending point of the selection, bottom right
  60. *
  61. ******************************************************************/
  62. GetRegion( regionhdl, startptr, endptr )
  63. RgnHandle            regionhdl ;
  64. Point                startptr;
  65. Point                endptr ;
  66. {
  67.     Rect            tempRect;
  68.     Point            rowstartptr;
  69.     Point            rowendptr ;
  70.     short            cellheight ;
  71.     short            right;
  72.     short            left;
  73.     short            rowselected ;
  74.     
  75.     cellheight = mycellSize.v ;
  76.         
  77.     left = _CACHEDESTRECT.left + myslop.h;
  78.     right = _CACHEDESTRECT.right - myslop.h;
  79.  
  80.     SwapPoint( &startptr, &endptr ) ;
  81.  
  82.     /* rowselected is at least one */
  83.     rowselected = (endptr.v - startptr.v) / cellheight + 1;
  84.  
  85.     OpenRgn();
  86.     
  87.     if ( rowselected == 1)
  88.     {
  89.         rowendptr = endptr ;
  90.         if ( rowendptr.v == startptr.v )
  91.             rowendptr.v += cellheight ;
  92.         Pt2Rect(startptr,rowendptr,&tempRect);
  93.         FrameRect(&tempRect);
  94.     }
  95.     else
  96.     {
  97.         rowendptr.h = right ;
  98.         rowendptr.v = startptr.v + cellheight ;
  99.         Pt2Rect(startptr,rowendptr,&tempRect);
  100.         FrameRect(&tempRect);
  101.         
  102.         if ( rowselected > 2 )
  103.         {
  104.             rowstartptr.h = left ;
  105.             rowstartptr.v = rowendptr.v ;
  106.             rowendptr.v = endptr.v ;
  107.             Pt2Rect(rowstartptr,rowendptr,&tempRect);
  108.             FrameRect(&tempRect);
  109.         }                                            /* if ( rowselected > 2 ) */
  110.         rowstartptr.v = endptr.v ;
  111.         rowstartptr.h = left;
  112.         endptr.v += cellheight ;
  113.         Pt2Rect(rowstartptr,endptr,&tempRect);
  114.         FrameRect(&tempRect);
  115.     }
  116.     CloseRgn( regionhdl );                
  117. }
  118.  
  119.  
  120. /******************************************************************
  121. *    CombineNewOldrgn()
  122. *        -    select the conbination region of oldregion and newregion 
  123. *
  124. *    inputs:
  125. *        newregion    -    new region to be combine and invert ( or select )
  126. *        oldregion    -    old region to be combine and invert ( or select )
  127. *
  128. ******************************************************************/
  129. CombineNewOldrgn( newregion, oldregion )
  130. RgnHandle            newregion ;
  131. RgnHandle            oldregion ;
  132. {
  133.     BitClr( (Ptr) HiliteMode, pHiliteBit ) ;
  134.     XorRgn(newregion,oldregion,oldregion);
  135.     InvertRgn(oldregion);    
  136. }
  137.  
  138.  
  139. /******************************************************************
  140. *    Cellboundary
  141. *        -    return the passed in point at the cell boundary
  142. *
  143. *    inputs:
  144. *        where    -    mouse point
  145. *
  146. ******************************************************************/
  147. Cellboundary( where )
  148. Point            *where;
  149. {
  150.     short        leftover;
  151.     short        halfcellwidth;
  152.     short        cellwidth;
  153.     Boolean        DonewithH;
  154.     short        left;
  155.     short        right;
  156.     short        bottom;
  157.     short        top;
  158.     
  159.     left = _CACHEDESTRECT.left + myslop.h;
  160.     if ( where->v  >= visCacheRect.bottom - CACHBOTTOMSLOP)
  161.     {
  162.         /* pin .h to the lower right bottom */
  163.         where->h = _CACHEDESTRECT.right - myslop.h;
  164.         DonewithH = true;
  165.     }
  166.     else if ( where->v <= visCacheRect.top )
  167.     {
  168.         where->h = left;
  169.         DonewithH = true;
  170.     }
  171.     
  172.     top = _CACHEDESTRECT.top;
  173.     bottom = _CACHEDESTRECT.bottom - CACHBOTTOMSLOP;
  174.     
  175.     if ( where->v > bottom )
  176.     {    
  177.         where->v = bottom-mycellSize.v;
  178.         if ( !DonewithH )
  179.         {
  180.             /* pin .h to the lower right bottom */
  181.             where->h = _CACHEDESTRECT.right - myslop.h;
  182.             DonewithH = true;
  183.         }                                /* if ( !DonewithH )  */
  184.     }
  185.     else if ( where->v < top )
  186.     {
  187.         where->v = top;
  188.         if ( !DonewithH )
  189.         {
  190.             /* pin .h to the lower right bottom */
  191.             where->h = left;
  192.             DonewithH = true;
  193.         }                                /* if ( !DonewithH ) */
  194.     }
  195.     else
  196.     {
  197.         where->v -= _CACHEDESTRECT.top ;
  198.         leftover = where->v % mycellSize.v ;
  199.         where->v -= leftover ;
  200.         where->v += _CACHEDESTRECT.top;
  201.     }
  202.     if ( !DonewithH )
  203.     {
  204.         if ( (where->h - left ) < 0 )
  205.         {
  206.             where->h = left;
  207.             return;
  208.         }
  209.         else 
  210.         {
  211.             right = _CACHEDESTRECT.right - myslop.h;
  212.             if ( where->h >  right  )
  213.             {
  214.                 where->h = right;
  215.                 return;
  216.             }
  217.         }
  218.         cellwidth = mycellSize.h;
  219.         where->h -= left;
  220.         leftover = where->h % cellwidth ;
  221.         where->h -= leftover ;
  222.         where->h += left;
  223.         halfcellwidth = cellwidth/2;            /* get half of the cell width */
  224.         if ( cellwidth % 2 )
  225.             halfcellwidth++;
  226.         if ( leftover > halfcellwidth )            /* is the point ends at more than half way thru the cell */
  227.         {
  228.             where->h += cellwidth ;                /* select the whole cell if so */
  229.         }
  230.     }                                            /* if ( !DonewithH ) */
  231. }
  232.  
  233.  
  234. /******************************************************************
  235. *    GetCell()
  236. *        -    return the cell in rows & columns for the passed in cell's location 
  237. *
  238. *    inputs:
  239. *        location    -    cell's location in pixel
  240. *        cellsize    -    current cellsize
  241. *
  242. *    returns:
  243. *        cell's location in row & columns
  244. *
  245. ******************************************************************/
  246. Point    GetCell( location, cellsize )
  247. Point    location;
  248. Point    cellsize;
  249. {
  250.     Point        cell;
  251.     
  252.     /* which row */
  253.     location.v -= _CACHEDESTRECT.top;
  254.     cell.v = location.v / cellsize.v;
  255.     /* which col */
  256.     location.h -= _CACHEDESTRECT.left + myslop.h;
  257.     cell.h = location.h / cellsize.h;
  258.     return cell;
  259. }
  260.  
  261. /******************************************************************
  262. *    GetCellPoint()
  263. *        -    return the cell's location in pixel 
  264. *
  265. *    inputs:
  266. *        cell        -    cell's location in rows and columns
  267. *        cellsize    -    current cellsize
  268. *    returns:
  269. *        cell's location in pixel
  270. *
  271. ******************************************************************/
  272. Point        GetCellPoint( cell, cellsize )
  273. Point        cell;
  274. Point        cellsize;
  275. {
  276.     Point        location;
  277.     
  278.     location.v = cell.v * cellsize.v + _CACHEDESTRECT.top;
  279.     location.h = cell.h * cellsize.h + _CACHEDESTRECT.left + myslop.h;
  280.     return location;
  281. }